<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>修改教师</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../css/index.css">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
</head>
<body>

  <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
      <label class="layui-form-label">教师工号</label>
      <div class="layui-input-inline">
        <input type="text" id="teacherid" name="teacherid" lay-verify="required" placeholder="教师工号不能为空" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">姓名</label>
      <div class="layui-input-inline">
        <input type="text" id="teachername" name="teachername" lay-verify="required" placeholder="姓名不能为空" autocomplete="off" class="layui-input">
      </div>
    </div>
     <div class="layui-form-item">
      <label class="layui-form-label">性别</label>
      <div class="layui-input-inline">
        <select id="agend" name="agend" lay-filter="agend" lay-verify="required">
          <option value="">请选择性别</option>
          <option value="1">男</option>
          <option value="2">女</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">电话号码</label>
      <div class="layui-input-inline">
        <input type="text" id="mobile" name="mobile"  lay-verify="required" placeholder="电话不能为空" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">所属学院</label>
      <div class="layui-input-inline">
         <select name="collegename" id="collegename" lay-filter="collegename" lay-verify="required">
                <option value="">请选择学院</option>
              </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">所属专业</label>
      <div class="layui-input-inline">
         <select name="professionalname" id="professionalname" lay-filter="professionalname" lay-verify="required">
          <option value="">请选择专业</option>
        </select>
      </div>
    </div>
   
    <div class="layui-form-item">
      <label class="layui-form-label">单位</label>
      <div class="layui-input-inline">
        <input type="text" id="unit" name="unit"  placeholder="单位不能为空" autocomplete="off" class="layui-input">
      </div>
     </div>
     <div class="layui-form-item">
     <div class="layui-form-item">
      <label class="layui-form-label">备注</label>
      <div class="layui-input-inline">
        <input type="text" id="note" name="note" autocomplete="off" class="layui-input">
      </div>
    </div>
    
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
      <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
  </div>

 <script type="text/javascript" src="../../layui/layui.all.js" charset="utf-8"></script> 

<script type="text/javascript">
 layui.use(['table','jquery','form','layer'], function(){
  var table = layui.table;
  var $ = layui.jquery;
  var form=layui.form;
  var layer = layui.layer;
  
    //监听提交,添加事件
    form.on('submit(layuiadmin-app-form-submit)', function(data){
      var field = data.field; //获取提交的字段
      var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
 			
 			if(!new RegExp("^1[345789]\\d{9}$").test(data.field.mobile)){
			     layer.msg("电话号码格式错误");
			      return;
			}
			
			
			var param = "?teacherid=" + field.teacherid + "&teachername=" + field.teachername + "&professionalid=" + field.professionalname + "&unit="
						+ field.unit + "&agend=" + field.agend + "&mobile=" + field.mobile + "&note=" + field.note;
			//alert(param)
			$.ajax({
				url:"../../teacherinfo/updateteacher" + param,
				type:"POST",
				data:null,
				dataType : "json",
				xhrFields :{
					withCredentials: true
				},
				contentType:'application/json;charset=UTF-8',
				success:function(e){
					//alert(e.msg)
					if(e.code == 0){
						layer.msg(e.msg,{icon:6}); 
					}else{
						layer.msg(e.msg,{icon:5});
						return;
					}
					
					setTimeout(function(){
						parent.layer.close(index); //再执行关闭 
						parent.layui.table.reload('teacherinfo'); //重载表格    					
					},1*1000)
					
				},
				error:function(e){
					layer.msg(e.msg,{icon:5});
					
				}
			})
      	return false;
    });
  
  
  
	  /*
	  *动态获取学院下拉框
	  */
	  $.ajax({
		type: 'get',
		url: '../../dropdown/getcollooge',
		datatype: 'json',
		success: function(roledata) {
			if(roledata.code == 0) {
				var str = "";
				for(var i = 0; i < roledata.count; i++) {
					str += '<option value=' + roledata.data[i].collegeid + '>' + roledata.data[i].collegename + '</option>';
				}
		   		 $("#collegename").append(str);
				form.render();
			} else {
					layer.msg("学院信息获取失败");
			}
		},
		error: function() {
			layer.msg("学院信息获取失败");
		}
	});

	/*
	* 动态获取专业信息
	*/
	$.ajax({
		type: 'get',
		url: '../../dropdown/getprofessional?collegeid=-1',
		datatype: 'json',
		success: function(roledata) {
			if(roledata.code == 0) {
				var str = "";
				for(var i = 0; i < roledata.count; i++) {
					str += '<option value=' + roledata.data[i].professionalid + '>' + roledata.data[i].professionalname + '</option>';
				}
		   		 $("#professionalname").append(str);
				form.render();
			} else {
					layer.msg("专业信息获取失败");
			}
		},
		error: function() {
			layer.msg("专业信息获取失败");
		}
	});
	
	//学院专业联动
	form.on('select(collegename)', function(data){
		//同时刷新两个数据，实现三级联动
   		 $.ajax({
			type: 'get',
			url: '../../dropdown/getprofessional?collegeid='+data.value,
			datatype: 'json',
			success: function(roledata) {
				if(roledata.code == 0) {
					var str = "";
					for(var i = 0; i < roledata.count; i++) {
						str += '<option value=' + roledata.data[i].professionalid + '>' + roledata.data[i].professionalname + '</option>';
					}
			   		 $("#professionalname option").remove();
			   		 $("#professionalname").append(str);
					 form.render();
				} else {
						layer.msg("专业信息获取失败");
				}
			},
			error: function() {
				layer.msg("专业信息获取失败");
			}
		});
	 })
	
});
</script>
</body>
</html>